package controller;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import po.Score;
import po.User;
import service.ScoreService;

@Controller
public class scoreController {
	
	// 依赖注入
	@Autowired
	private ScoreService scoreService;	
	@RequestMapping(value = "/score/getScore.action")
	public String list( Model model) {
		List<Score> scorelist = scoreService.getScoreList();
		model.addAttribute("scorelist", scorelist);	
		return "score_list";

	}
	@RequestMapping("/score/delScore.action")
	public String scoreDelete(Integer scoreid) {
		int rows = scoreService.deleteScore(scoreid);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/score/getScore.action";
	}
	@RequestMapping("/score/addScore.action")
	public String scoreAdd(Score score) {
		int rows = scoreService.addScore(score);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/score/getScore.action";
	}
	
	@RequestMapping(value ="/score/getscoreId.action")
	@ResponseBody
	public Score getScoreId(Integer id) {
		Score data = scoreService.getScoreId(id);
		return data;
   }  
	
	@RequestMapping(value ="/score/updateScore.action")
	@ResponseBody
	public String updateScore(Score score) {
		int row = scoreService.updateScore(score);
		if(row>0) {
			return "OK";
		}else {
			return "false";
		}
   }
	@RequestMapping(value = "/score/findAll.action")
	public String listAll(String data,Model model) {	
		List<Score> scorelist = scoreService.findList(data);
		model.addAttribute("scorelist", scorelist);	
		return "score_list";
	}
}
